//
//  SettingToggleSView.swift
//  BasicTools
//
//  Created by ikang on 2025/8/27.
//

import SwiftUI

struct SettingToggleSView: View {
    @Bindable var itemModel: SettingItemModel
    var isShowLine: Bool = false
    
    var body: some View {
        
        Toggle(isOn: $itemModel.isOn) { 
            HStack(spacing: SettingModel.shared.itemHSpace) { 
                if !itemModel.leftImage.isEmpty {
                    Image(itemModel.leftImage)
                        .resizable()
                        .aspectRatio(contentMode: .fit)
                        .frame(width: SettingModel.shared.leftImageSize.width, height: SettingModel.shared.leftImageSize.height)
                }
                
                VStack(spacing: SettingModel.shared.itemTitleSpace) { 
                    if !itemModel.title.isEmpty {
                        Text(itemModel.title)
                            .font(SettingModel.shared.titleFont)
                            .foregroundStyle(SettingModel.shared.titleColor)
                    }
                    
                    if !itemModel.subTitle.isEmpty {
                        Text(itemModel.subTitle)
                            .font(SettingModel.shared.subTitleFont)
                            .foregroundStyle(SettingModel.shared.subTitleColor)
                    }
                }
                
                Spacer()
            }
        }
        .toggleStyle(.switch)
        .padding(SettingModel.shared.itemPadding)
        .bt.lineModifier(lineHeight: SettingModel.shared.itemLineHeight, backgroundColor: SettingModel.shared.itemLineColor, padding: SettingModel.shared.itemLinePadding, isShowLine: isShowLine)
        .onChange(of: itemModel.isOn) { oldValue, newValue in
            
        }
    }
}

//#Preview {
//    SwiftUIView()
//}
